<template>
  <div>
    <el-dialog
      :title="title"
      :visible.sync="dialogVisible"
      width="84rem"
      :before-close="tableClose"
    >
      <el-form
        :model="addForm"
        status-icon
        :rules="rules"
        ref="addInfoRef"
        label-width="8rem"
      >
        <!-- 第一行 -->
        <el-row>
          <el-col :span="10" :offset="1">
            <el-form-item
              label="加工厂编号"
              prop="processingId"
              :rules="{
                required: true,
                message: '不能为空',
                trigger: 'blur',
              }"
            >
              <el-input v-model="addForm.processingId" :disabled="true"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10" :offset="1">
            <el-form-item
              label="规格"
              prop="specification"
              :rules="{
                required: true,
                message: '不能为空',
                trigger: 'blur',
              }"
            >
              <el-input
                v-model="addForm.specification"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 第二行 -->
        <el-row>
          <el-col :span="10" :offset="1">
            <el-form-item
              label="产品编号"
              prop="typeId"
              :rules="{
                required: true,
                message: '不能为空',
                trigger: 'blur',
              }"
            >
              <el-input
                v-model="addForm.typeId"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10" :offset="1">
            <el-form-item
              label="产品名称"
              prop="typeName"
              :rules="{
                required: true,
                message: '不能为空',
                trigger: 'blur',
              }"
            >
              <el-input
                v-model="addForm.typeName"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 第三行 -->
        <el-row>
          <el-col :span="10" :offset="1">
            <el-form-item
              label="成本价"
              prop="price"
              :rules="{
                required: true,
                message: '不能为空',
                trigger: 'blur',
              }"
            >
              <el-input
                v-model="addForm.price"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10" :offset="1">
            <el-form-item
              label="参考价"
              prop="referPrice"
            >
              <el-input
                type="textarea"
                :rows="1"
                v-model="addForm.referPrice"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 第四行 -->
        <el-row>
          <el-col :span="10" :offset="1">
            <el-form-item
              label="预售价"
              prop="preprice"
              :rules="{
                required: true,
                message: '不能为空',
                trigger: 'blur',
              }"
            >
              <el-input
                v-model="addForm.preprice"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10" :offset="1">
            <el-form-item
              label="总金额"
              prop="total"
            >
              <el-input
                type="textarea"
                :rows="1"
                v-model="addForm.total"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 第五行 -->
        <el-row>
          <el-col :span="10" :offset="1">
            <el-form-item
              label="库存数量"
              prop="count"
              :rules="{
                required: true,
                message: '不能为空',
                trigger: 'blur',
              }"
            >
              <el-input
                v-model="addForm.count"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10" :offset="1">
            <el-form-item
              label="库存备注"
              prop="remark"
            >
              <el-input
                type="textarea"
                :rows="1"
                v-model="addForm.remark"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="tableClose">取 消</el-button>
        <el-button type="primary" @click="addOrderInfo()">提 交</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  addEvent 
} from "@/api/Process/processManage"

export default {
  name: "storageInpopup",
  props: {
    addForm: {
      Object,
      default: {},
    },
    dialogVisible: {
      Boolean,
      default: false,
    },
    //表名
    title: {
      String,
      default: "",
    },
  },
  data() {
    return {
      //表单规则
      rules: {
        materialName: [
          { required: true, message: "不能为空", trigger: "blur" },
        ],
        specification: [
          { required: true, message: "不能为空", trigger: "blur" },
        ],
        count: [{ required: true, message: "不能为空", trigger: "blur" }],
        price: [{ required: true, message: "不能为空", trigger: "blur" }],
        remark: [{ required: true, message: "不能为空", trigger: "blur" }],
        enterTime: [{ required: true, message: "不能为空", trigger: "blur" }],
        typeId: [{ required: true, message: "不能为空", trigger: "blur" }],
        batchId: [{ required: true, message: "不能为空", trigger: "blur" }],
        total: [{ required: true, message: "不能为空", trigger: "blur" }],
      },
    };
  },
  methods: {
    // //查询表格数据
    addDisplayData() {
      this.$emit("addDisplayData");
      console.log("查询表格数据");
    },
    // 添加订单
    addOrderInfo() {
      var time = new Date(this.addForm.enterTime);
      var enTime = this.getTime(time);
      this.addForm.enterTime = enTime;
      this.$refs["addInfoRef"].validate(async (valid) => {
        if (valid) {
          console.log("新增提交的订单", this.addForm);
          const { data: res } = await addEvent(this.addForm);
          console.log(res);
          if (res.statusCode === 20000) {
            this.$message.success("增加成功");
            this.closeform();
          } else {
            if (res.data === null) {
              return this.$message.error("添加失败");
            }
          }
        }
      });
    },

    //删除记录
    removeDomain(index) {
      this.addForm.inProcessingBills.splice(index, 1);
    },
    // 获取指定时间
    getTime(time) {
      var currentTime = new Date(time);
      this.nHour = currentTime.getHours();
      this.nHour = this.nHour < 10 ? "0" + this.nHour : this.nHour;
      this.nMinute = currentTime.getMinutes();
      this.nMinute = this.nMinute < 10 ? "0" + this.nMinute : this.nMinute;
      this.nSecond = currentTime.getSeconds();
      this.nSecond = this.nSecond < 10 ? "0" + this.nSecond : this.nSecond;
      this.nYear = currentTime.getFullYear();
      this.nMonth = currentTime.getMonth() + 1;
      this.nMonth = this.nMonth < 10 ? "0" + this.nMonth : this.nMonth;
      this.nDay = currentTime.getDate();
      this.nDay = this.nDay < 10 ? "0" + this.nDay : this.nDay;
      var rtnTime =
        this.nYear +
        "-" +
        this.nMonth +
        "-" +
        this.nDay +
        " " +
        this.nHour +
        ":" +
        this.nMinute +
        ":" +
        this.nSecond;
      return rtnTime;
    },
    //重置
    resetForm() {
      this.$nextTick(() => {
        this.$refs.addInfoRef.resetFields();
      });
    },
    //关闭表单
    closeform() {
      var a = false;
      this.$emit("closeAddDialog", a);
      this.addDisplayData();
      this.resetForm();
    },

    // 关闭弹窗
    tableClose() {
      // this.$confirm("确认关闭？")
      //   .then(() => {
      //     this.closeform();
      //   })
      //   .catch(() => {});
      var a = false;
      this.$emit("closeAddDialogB", a);
      this.resetForm();
    },
  },
};
</script>

<style lang="scss" scoped>
</style>